<?php


namespace app\controller;


use app\BaseController;
use app\common\constants\ReturnCodeConstants;
use app\common\util\Sign;
use app\common\util\HttpRequest;
use app\common\util\Response;

class UrlSignExample extends BaseController
{
    public function example()
    {
        //密钥
        $appSecret = 'UrlSignExample';

        /**
         * 生成url签名
         */
        //请求地址
        $url = 'https://www.baidu.com';
        $url = Sign::makeUrl($url, $appSecret);
        (new HttpRequest())->get($url);

        /**
         * 校验url签名
         */
        $params = $this->request->get();
        $result = Sign::verifySign($params, $appSecret);
        if ($result !== true) {
            return Response::failureJson(ReturnCodeConstants::C_P_VERIFY_FAIL, $result);
        }
        return Response::successJson();
    }


}